<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
<%@ taglib prefix="shiro" uri="http://www.springside.org.cn/tags/shiro" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<c:set var="ctx" value="${r"${pageContext.request.contextPath}"}"/>

<html>
<head>
	<title>管理</title>

	<!-- 使用bootbox的增强式alert/confirm/prompt -->	
	<script src="${r"${ctx}"}/static/metronic/assets/plugins/bootbox/bootbox.min.js" type="text/javascript"></script>
	<script>
	//http://bootboxjs.com/
	function publish(id){
		bootbox.confirm("确实发布这条产品？", function(result) {
            if(result){
				location.href = "${r"${ctx}"}/${path}/publish/" + id;
            }
        }); 
	}
	</script>
	
	<!-- select2组合框 -->
	<link rel="stylesheet" type="text/css" href="${r"${ctx}"}/static/metronic/assets/plugins/select2/select2_metro.css"/>
	<script type="text/javascript" src="${r"${ctx}"}/static/metronic/assets/plugins/select2/select2.min.js"></script>
	
</head>

<body>
<!-- BEGIN CONTENT -->
	<div class="page-content-wrapper">
		<div class="page-content">
			<!-- 提示信息 -->
			<c:if test="${r"${not empty message}"}">
				<div id="message" class="alert alert-success"><button data-dismiss="alert" class="close">×</button>${r"${message}"}</div>
			</c:if>
			
			<!-- 查询表单 -->
			<div class="portlet-body">
			<form class="form-inline" action="#">
				<div class="form-group">
					<label class="sr-only" for="search_name">名称</label>
					<input type="text" id="search_name" name="search_name" class="form-control" placeholder="按名称查询" value="${r"${param.search_name}"}"/>
				</div>
				
				<div class="form-group">
					<label class="sr-only" for="search_isenabled">状态</label>
					<select name="search_isenabled" id="search_industry" class="form-control input-small select2me" data-placeholder="按发布状态查询">
						<option value="">全部状态</option>
						<option value="0" >草稿</option>
						<option value="1" >已发布</option>
					</select>
				</div>
				<button type="submit" class="btn btn-default">查询</button>
			</form>
			</div>
			
			<hr>
			
			<shiro:hasPermission name="${path}:add">
			<div class="row list-buttons">
				<div class="col-md-12">
					<a href="${r"${ctx}"}/${path}/create" class="btn green">新建</a>
					<a href="${r"${ctx}"}/${path}/import" class="btn green">导入</a>
				</div>
			</div>
			</shiro:hasPermission>
			
			<!-- 数据表格 -->
			<!-- BEGIN PAGE HEADER-->
			<div class="row">
				<div class="col-md-12">
					<!-- BEGIN SAMPLE TABLE PORTLET-->
					<div class="portlet box green">
						<div class="portlet-title">
							<div class="caption">
								<i class="fa fa-cogs"></i>列表
							</div>
						</div>
						<div class="portlet-body">
							<div class="table-responsive">
								<table class="table table-hover">
								<thead>
								<tr>
									<#list fields as map>
											<#list map?keys as name>
										      <th>${map[name]}</th>
										    </#list>
										 </#list>
									<th>状态</th>
								<shiro:hasAnyPermissions name="${path}:delete,${path}:add">
									<th>管理</th>
								</shiro:hasAnyPermissions>
								</tr>
								</thead>
								<tbody>
								
								<c:forEach items="${r"${"}${list}${r".content}"}" var="value">
								<tr>
									
									<#list fields as map>
										<#list map?keys as name>
										      <#if map[name]?contains("name")>
													<td>
														<shiro:hasPermission name="${path}:edit">
															<a href="${r"${ctx}"}/${path}/update/${r"${value"}${r".id}"}" class="btn default btn-xs purple"><i class="fa fa-edit"> </i> ${r"${value."}${map[name]}${r"}"}</a>
														</shiro:hasPermission>
														<shiro:lacksPermission name="${path}:edit">
															<a href="${r"${ctx}"}/${path}/view/${r"${value"}${r".id}"}" class="btn default btn-xs blue"><i class="fa fa-search"> </i>${r"${value."}${map[name]}${r"}"}</a>
														</shiro:lacksPermission>
													</td>
													<#else>
														<td>${r"${value."}${map[name]}${r"}"}</td>
											</#if>
									    </#list>
									 </#list>
									<td>
										<span class="label label-sm label-${r"${value.isenabled"}==0?'info':'success'}">
											${r"${value.isenabled"}==0?'草稿':'已发布'}
										</span>
									</td>
									<shiro:hasAnyPermissions name="${path}:delete,${path}:add">
									<td>
										<shiro:hasPermission name="${path}:delete">
											<a href="${r"${ctx}"}/${path}/delete/${r"${value"}${r".id}"}" class="btn default btn-xs black"><i class="fa fa-trash-o"> </i> 删除</a>
										</shiro:hasPermission>
										<c:if test="${r"${value.isenabled==0}"}">
											<shiro:hasPermission name="${path}:add">
												<a href="javascript:publish(${r"${value"}${r".id}"})" class="btn default btn-xs blue"><i class="fa fa-share"> </i> 发布</a>
											</shiro:hasPermission>
										</c:if>
									</td>
									</shiro:hasAnyPermissions>
								</tr>
								</c:forEach>	
								</tbody>
								</table>
							</div>
						</div>
					</div>
					<!-- END SAMPLE TABLE PORTLET-->
				</div>
			</div>
			
			<tags:pagination page="${r"${"}${list}${r"}"}" paginationSize="5"/>
	
		</div>
	</div>
</body>
</html>
